package com.ymatou.iapi.optrade.testcase;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.delivery.service.DeliveryService;
import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFeeTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.AuthenticateFreightTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.ApplyRefundReq;
import com.ymatou.iapi.optrade.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.optrade.parameter.req.ValidateRefundV2Req;
import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymatou.iapi.optrade.parameter.vo.OrderGroupVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderVo;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.optrade.service.BargainGroupService;
import com.ymatou.iapi.optrade.service.RefundService;
import com.ymatou.iapi.optrade.service.ValidateRefundV2Call;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAnliOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceAuthenticateCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.business.service.YMTTrading.TradingProductVo;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 退货退款申请效验接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ValidateRefundV2 {

	private static ValidateRefundV2Req validateRefundReq;
	private static ValidateRefundV2Call applyvalidationCall;
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	
	private static long userId = 20238699;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退货退款申请校验接口（买家用）");
	}

	@Before
	public void caseUp() {
		validateRefundReq = new ValidateRefundV2Req();
		applyvalidationCall = new ValidateRefundV2Call();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applyvalidationCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 计算商品最大可退金额
	 * 
	 * @param po
	 * @return
	 */
	public static BigDecimal getOrderDetailPaidAmountExcludeFreight(
			OrderDetailPo po, int productCount) {

		BigDecimal refundAmount = Utils.zeroIfNull(po.getProductPrice())
				.multiply(new BigDecimal(po.getProductCount()))
				.add(Utils.zeroIfNull(po.getDiscount()))
				.subtract(Utils.zeroIfNull(po.getYmtCouponAmount()))
				.subtract(Utils.zeroIfNull(po.getSellerCouponAmount()))
				.subtract(Utils.zeroIfNull(po.getPromotionAmount()))
				.subtract(Utils.zeroIfNull(po.getThirdpartyDiscount()))
				.subtract(Utils.zeroIfNull(po.getYmtPromotionAmount()));

		if (po.getProductCount() != productCount) {

			refundAmount = refundAmount
					.divide(new BigDecimal(po.getProductCount()),
							MathContext.DECIMAL32)
					.setScale(2, RoundingMode.DOWN)
					.multiply(new BigDecimal(productCount));

		}

		return refundAmount;

	}

	/**
	 * 计算商品最大可退运费
	 * 
	 * @param po
	 * @return
	 */
	public static BigDecimal getMaxCanRefundFreight(Order order,
			BigDecimal productFreight) {

		long orderId = order.getOrderId();

		if (BigDecimal.ZERO.compareTo(productFreight) == 0) {

			return BigDecimal.ZERO;

		}

		List<RefundBillPo> res = orderShardingWapper
				.selectRefundBillListByOrderId(orderId);

		BigDecimal freight = res
				.stream()
				.filter(r -> r.getRefundBillStatus() == 1
						|| r.getRefundBillStatus() == 10)
				.map(f -> f.getFreight())
				.reduce(BigDecimal.ZERO, BigDecimal::add);

		return order.getOrderFreight().subtract(freight);

	}
	
	/**
	 * 计算商品最大可退鉴定费（包括鉴定费和鉴定运费）
	 * 
	 * @param po
	 * @return
	 */
	public static BigDecimal getMaxCanRefundAuthenticateFee(
			Order order, OrderDetailPo orderDetailPo) {
		
		if (Utils.zeroIfNull(orderDetailPo.getAuthenticateFeeType()) == AuthenticateFeeTypeEnum.BUYER
				.getCode()) {
			
			// 计算最大可退的商品鉴定费
			BigDecimal maxProductCanRefundAuthenticateFee = Utils.zeroIfNull(orderDetailPo
					.getAuthenticateFee()).multiply(
							new BigDecimal(validateRefundReq.getApplyRefundCount()));
			BigDecimal authenticateFeeFreight = BigDecimal.ZERO;
			
			Long orderId = order.getOrderId();
			List<OrderDetailPo> orderDetailList = order.getOrderDetailPoList();
			
			// 如果所有的鉴定商品都退掉了，则退掉鉴定运费
			// 如果这个订单只有一个商品
			if (orderDetailList.size() == 1) {

				// 查询该商品是否发生过退款，如果这个商品已经有退款
				List<RefundBillPo> refundBillPoList = orderShardingWapper
						.selectRefundBillListByOrderIdAndCatalogId(orderId,
								validateRefundReq.getCatalogId());

				if (refundBillPoList.size() == 0) {
					// 如果申请的数量=商品数量，可退鉴定运费
					if (validateRefundReq.getApplyRefundCount() == orderDetailPo
							.getProductCount())
						authenticateFeeFreight = order
								.getUserAuthenticateFreightFee();
				} else {

					// 如果这个商品已经有退款，将退款中和退款完成的商品数量加起来
					Integer refundedProductCount = refundBillPoList
							.stream()
							.filter(refundBillPo -> refundBillPo
									.getRefundBillStatus() == 1
									|| refundBillPo.getRefundBillStatus() == 10)
							.map(refundBillPo -> refundBillPo.getProductCount())
							.reduce(0, Integer::sum);

					// 如果申请的数量=商品数量-已经退款的数量，可退鉴定运费
					if (validateRefundReq.getApplyRefundCount() == orderDetailPo
							.getProductCount() - refundedProductCount)
						authenticateFeeFreight = order
								.getUserAuthenticateFreightFee();
					else
						authenticateFeeFreight = BigDecimal.ZERO;
				}
				
				// 如果是鉴别中心发货，不退鉴别运费
				if (DeliveryService.isAuthenticateDelivery(orderId))
					authenticateFeeFreight = BigDecimal.ZERO;
			} else {
				
				// 查询订单是否发生过退款
				List<RefundBillPo> refundBillPoList = orderShardingWapper
						.selectRefundBillListByOrderId(orderId);
				Boolean otherAllRefunded = false;
				
				if (refundBillPoList.size() > 0) {
					
					// 其他买家鉴定费商品
					List<OrderDetailPo> otherOrderDetailList = orderDetailList
							.stream()
							.filter(orderDetail -> !orderDetail.getCatalogId()
									.equalsIgnoreCase(
											validateRefundReq.getCatalogId())
									&& (Utils.zeroIfNull(orderDetail
											.getAuthenticateFeeType()) == AuthenticateFeeTypeEnum.BUYER
											.getCode()))
							.collect(Collectors.toList());
					
					// 如果订单下其他买家鉴定费商品发生退款
					if (null != otherOrderDetailList && otherOrderDetailList.size() > 0) {
						
						// 校验其他商品数量是否全部发生退款
						for (int i = 0; i < otherOrderDetailList.size(); i++) {
							
							OrderDetailPo otherOrderDetailPo = otherOrderDetailList.get(i);

							List<RefundBillPo> otherOrderDetaiRefundList = refundBillPoList
									.stream()
									.filter(refundBillPo -> refundBillPo
											.getCatalogId().equalsIgnoreCase(
													otherOrderDetailPo
															.getCatalogId())
											&& (refundBillPo
													.getRefundBillStatus() == 1 || refundBillPo
													.getRefundBillStatus() == 10))
									.collect(Collectors.toList());
							
							// 如果某个商品发生了退货退款
							if (null != otherOrderDetaiRefundList && otherOrderDetaiRefundList.size() > 0) {
								
								Integer otherOrderDetailRefundedCount = otherOrderDetaiRefundList
										.stream()
										.map(refundBillPo -> refundBillPo
												.getProductCount())
										.reduce(0, Integer::sum);
								
								if (otherOrderDetailRefundedCount == otherOrderDetailPo
										.getProductCount())
									otherAllRefunded = true;
								else {
									
									// 只要有一个商品没有全部退货退款，break
									otherAllRefunded = false;
									break;
								}
							} else
								otherAllRefunded = false;
						}
						
						// 如果订单下所有的其他商品都已经退货退款
						if (otherAllRefunded) {
							
							// 查询该商品是否发生过退款，如果这个商品已经有退款
							List<RefundBillPo> refundApplyBillPoList = orderShardingWapper
									.selectRefundBillListByOrderIdAndCatalogId(
											orderId,
											validateRefundReq.getCatalogId());

							if (null == refundApplyBillPoList) {
								// 如果申请的数量=商品数量，可退鉴定运费
								if (validateRefundReq.getApplyRefundCount() == orderDetailPo
										.getProductCount())
									authenticateFeeFreight = order
											.getUserAuthenticateFreightFee();
							} else {

								// 如果这个商品已经有退款，将退款中和退款完成的商品数量加起来
								Integer refundedProductCount = refundApplyBillPoList
										.stream()
										.filter(refundBillPo -> refundBillPo
												.getRefundBillStatus() == 1
												|| refundBillPo
														.getRefundBillStatus() == 10)
										.map(refundBillPo -> refundBillPo
												.getProductCount())
										.reduce(0, Integer::sum);

								// 如果申请的数量=商品数量-已经退款的数量，可退鉴定运费
								if (validateRefundReq.getApplyRefundCount() == orderDetailPo
										.getProductCount()
										- refundedProductCount)
									authenticateFeeFreight = order
											.getUserAuthenticateFreightFee();
								else
									authenticateFeeFreight = BigDecimal.ZERO;
							}
							
							// 如果是鉴别中心发货，不退鉴别运费
							if (DeliveryService.isAuthenticateDelivery(orderId))
								authenticateFeeFreight = BigDecimal.ZERO;
							
						} else {
							
							authenticateFeeFreight = BigDecimal.ZERO;
						}
					} else 
						authenticateFeeFreight = BigDecimal.ZERO;
				} else {
					
					// 如果其他商品没有发生过退款
					if (validateRefundReq.getApplyRefundCount() == Utils.zeroIfNull(orderDetailPo.getProductCount()))
						authenticateFeeFreight = order.getUserAuthenticateFreightFee();
					else
						authenticateFeeFreight = BigDecimal.ZERO;
				}
			}

			return maxProductCanRefundAuthenticateFee.add(authenticateFeeFreight);
			
		} else {

			BigDecimal authenticateFeeFreight = BigDecimal.ZERO;

			Long orderId = order.getOrderId();
			List<OrderDetailPo> orderDetailList = order.getOrderDetailPoList();

			// 如果所有的商品都退掉了，则退掉鉴定运费
			// 如果这个订单只有一个商品
			if (orderDetailList.size() == 1) {

				authenticateFeeFreight = BigDecimal.ZERO;
			} else {

				// 查询订单是否发生过退款
				List<RefundBillPo> refundBillPoList = orderShardingWapper
						.selectRefundBillListByOrderId(orderId);
				Boolean otherAllRefunded = false;

				if (refundBillPoList.size() > 0) {

					List<OrderDetailPo> otherOrderDetailList = orderDetailList
							.stream()
							.filter(orderDetail -> !orderDetail.getCatalogId()
									.equalsIgnoreCase(
											validateRefundReq.getCatalogId()))
							.collect(Collectors.toList());

					// 如果订单下其他商品发生退款
					if (null != otherOrderDetailList
							&& otherOrderDetailList.size() > 0) {

						// 校验其他商品数量是否全部发生退款
						for (int i = 0; i < otherOrderDetailList.size(); i++) {

							OrderDetailPo otherOrderDetailPo = otherOrderDetailList
									.get(i);

							List<RefundBillPo> otherOrderDetaiRefundList = refundBillPoList
									.stream()
									.filter(refundBillPo -> refundBillPo
											.getCatalogId().equalsIgnoreCase(
													otherOrderDetailPo
															.getCatalogId())
											&& (refundBillPo
													.getRefundBillStatus() == 1 || refundBillPo
													.getRefundBillStatus() == 10))
									.collect(Collectors.toList());

							// 如果某个商品发生了退货退款
							if (null != otherOrderDetaiRefundList
									&& otherOrderDetaiRefundList.size() > 0) {

								Integer otherOrderDetailRefundedCount = otherOrderDetaiRefundList
										.stream()
										.map(refundBillPo -> refundBillPo
												.getProductCount())
										.reduce(0, Integer::sum);

								if (otherOrderDetailRefundedCount == otherOrderDetailPo
										.getProductCount())
									otherAllRefunded = true;
								else {

									// 只要有一个商品没有全部退货退款，break
									otherAllRefunded = false;
									break;
								}
							} else
								otherAllRefunded = false;
						}

						// 如果订单下所有的其他商品都已经退货退款
						if (otherAllRefunded) {

							// 查询该商品是否发生过退款，如果这个商品已经有退款
							List<RefundBillPo> refundApplyBillPoList = orderShardingWapper
									.selectRefundBillListByOrderIdAndCatalogId(
											orderId,
											validateRefundReq.getCatalogId());

							if (null == refundApplyBillPoList) {
								// 如果申请的数量=商品数量，可退鉴定运费
								if (validateRefundReq.getApplyRefundCount() == orderDetailPo
										.getProductCount())
									authenticateFeeFreight = order
											.getUserAuthenticateFreightFee();
							} else {

								// 如果这个商品已经有退款，将退款中和退款完成的商品数量加起来
								Integer refundedProductCount = refundApplyBillPoList
										.stream()
										.filter(refundBillPo -> refundBillPo
												.getRefundBillStatus() == 1
												|| refundBillPo
														.getRefundBillStatus() == 10)
										.map(refundBillPo -> refundBillPo
												.getProductCount())
										.reduce(0, Integer::sum);

								// 如果申请的数量=商品数量-已经退款的数量，可退鉴定运费
								if (validateRefundReq.getApplyRefundCount() == orderDetailPo
										.getProductCount()
										- refundedProductCount)
									authenticateFeeFreight = order
											.getUserAuthenticateFreightFee();
								else
									authenticateFeeFreight = BigDecimal.ZERO;
							}

						} else {

							authenticateFeeFreight = BigDecimal.ZERO;
						}
					} else
						authenticateFeeFreight = BigDecimal.ZERO;
				} else
					authenticateFeeFreight = BigDecimal.ZERO;
			}

			return authenticateFeeFreight;
		}
	}

	/**
	 * 
	 * @param order
	 * @param orderDetailPo
	 * @param refundCount
	 */
	private void verify(Order order, OrderDetailPo orderDetailPo,
			int refundCount) {

		BigDecimal maxCanRefundAmount = getOrderDetailPaidAmountExcludeFreight(
				orderDetailPo, refundCount);

		BigDecimal maxCanRefundFreight = getMaxCanRefundFreight(order,
				orderDetailPo.getFreight());
		
		BigDecimal maxCanRefundAuthenticateFee = getMaxCanRefundAuthenticateFee(
				order, orderDetailPo);

		Logger.verifyEquals("true", applyvalidationCall.getString("success"),
				"验证返回码");

		DataUtil.verifyDecimalEquals(maxCanRefundAmount, new BigDecimal(
				applyvalidationCall.getString("maxCanRefundAmount")),
				"验证maxCanRefundAmount");

		DataUtil.verifyDecimalEquals(maxCanRefundFreight, new BigDecimal(
				applyvalidationCall.getString("maxCanRefundFreight")),
				"验证maxCanRefundFreight");
		
		DataUtil.verifyDecimalEquals(maxCanRefundAuthenticateFee, new BigDecimal(
				applyvalidationCall.getString("maxCanRefundAuthenticateFee")),
				"验证maxCanRefundAuthenticateFee");
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_001() {
		Logger.start(true, "用户下单后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithCoupon();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_002() {
		Logger.start(true, "用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService.payOrder();
			Order order = placeOrderResp.getOrderList().get(0);
			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_003() {
		Logger.start(true, "商家接单前取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.cancelOrderBeforePaid(CancelOrderTypeEnum.BUYER_CANCEL_ORDER);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s已取消，不能退货退款", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_004() {
		Logger.start(true, "商家接单后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {

			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_005() {
		Logger.start(true, "商家接单后取消订单,效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();

			// 取消订单
			TradingCallService.cancelOrder(orderId,
					CancelOrderTypeEnum.CUSTOMER_CANCEL_ORDER, userId);

			Logger.comment("前置数据准备结束");
			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s已取消，不能退货退款", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_006() {
		Logger.start(false, "订单退货退款中,申请校验的金额小于等于可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 付款
			TradingCallService.payOrder(userId, amount, tradingId);

			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			BigDecimal maxCanRefundAmount = getOrderDetailPaidAmountExcludeFreight(
					placeOrderResp.getOrderList().get(0).getOrderDetailPoList()
							.get(0), validateRefundReq.getApplyRefundCount());

			BigDecimal maxCanRefundFreight = getMaxCanRefundFreight(order,
					order.getOrderDetailPoList().get(0).getFreight());

			Logger.verifyEquals("true",
					applyvalidationCall.getString("success"), "验证返回码");

			DataUtil.verifyDecimalEquals(maxCanRefundAmount, new BigDecimal(
					applyvalidationCall.getString("maxCanRefundAmount")),
					"验证maxCanRefundAmount");

			DataUtil.verifyDecimalEquals(maxCanRefundFreight, new BigDecimal(
					applyvalidationCall.getString("maxCanRefundFreight")),
					"验证maxCanRefundFreight");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_007() {
		Logger.start(false, "订单退货退款中,申请校验的金额大于最大可退款金额");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderApplyRefund();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(2);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_008() {
		Logger.start(true, "用户收货之后申请校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_009() {
		Logger.start(false, "订单号不存在申请效验");
		try {

			validateRefundReq.setOrderId(11111);
			validateRefundReq.setCatalogId("123");
			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", 11111));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderNotExists",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单不存在", validateRefundReq.getOrderId()),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ValidateRefundV2_010() {
		Logger.start(false, "订单号为null申请效验");
		try {
			// validateRefundReq.setOrderId(111111);
			validateRefundReq.setCatalogId("123");
			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", 11111));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("orderId:订单号未提供",
							validateRefundReq.getOrderId()),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_014() {
		Logger.start(true, "商家发货后,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderDelivery();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_015() {
		Logger.start(true, "确认收货15天内,退货退款校验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderConfirmReceive();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			new DefaultWapper().updateOrderConfirmedTimeByOrderId(orderId);

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

			OrderPo record = new OrderPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -10);
			;

			record.setOrderId(orderId);
			record.setReceiveTime(calendar.getTime());

			orderShardingWapper.orderMapper.updateByPrimaryKeySelective(record);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_017() {
		Logger.start(true, "商品申请退款金额大于(商品可退金额+订单总运费)");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			Logger.comment("前置数据准备结束");

			// 第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			validateRefundReq.setApplyRefundAmount(orderInfoPo
					.getProductPrice()
					.multiply(new BigDecimal(orderInfoPo.getProductCount()))
					.add(order.getOrderFreight()).add(BigDecimal.ONE));
			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_018() {
		Logger.start(true, "订单商品不是包邮,商品退款加退部分商品运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(refundProductFreight
					.add(refoundAmout));

			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_019() {
		Logger.start(true, "订单商品不是包邮,商品退款及退超过商品的运费，但不超过订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(refundProductFreight
					.add(refoundAmout));

			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_020() {
		Logger.start(true, "退款商品数量大于实际数量");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount() + 1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_CONDITION_NOTMATCH",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退商品数量不能大于实际商品数量", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_021() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund);

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_022() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加部分商品运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.subtract(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额

			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);
			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(refundProductFreight));

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_023() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加上不超过订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal productFreight = orderInfoPo.getFreight();

			BigDecimal refundProductFreight = productFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(refundProductFreight));
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));
			validateRefundReq.setApplyRefundCount(1);

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_024() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			BigDecimal orderFreight = order.getOrderFreight();

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(orderFreight));

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_025() {
		Logger.start(true, "订单商品不是包邮,申请单个商品退款加上超过订单总运费");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(false,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			Order order = placeOrderResp.getOrderList().get(0);

			BigDecimal orderFreight = order.getOrderFreight();

			Long orderId = order.getOrderId();

			// 支付
			TradingCallService.payOrder(placeOrderResp.getUserId(),
					placeOrderResp.getPayableAmount(),
					placeOrderResp.getTradingId());
			// 接单
			TradingCallService.sellerAcceptOrder(order.getSellerId(), orderId);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			BigDecimal refundProductFreight = orderFreight
					.add(new BigDecimal(2));

			// 计算订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund
					.add(refundProductFreight));

			validateRefundReq
					.setApplyRefundCount(orderInfoPo.getProductCount());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_026() {
		Logger.start(true, "订单锁定后申请效验");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingCallService
					.orderAccept();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			// 锁定订单
			TradingCallService.markOrderLock(orderId, 1);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("该订单已被客服锁定，暂时无法对该订单进行后续操作",
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_027() {
		Logger.start(true, "虚拟商品不能发起退货退款");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ValidateRefundV2_028() {
		Logger.start(true, "订单里有包邮非包邮混合商品,包邮商品全退+退部分运费");
		try {

			TradingServiceResp placeOrderResp = Ts_ApplySalesRefund
					.placeOrder3();

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long orderId = order.getOrderId();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 付款
			TradingCallService.payOrder(userId, amount, tradingId);
			// 卖家接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);

			validateRefundReq.setOrderId(orderId);

			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(1);

			String catalogId = orderDetailPo.getCatalogId();

			int productNum = orderDetailPo.getProductCount();

			// 可以退款的订单总价格 商品价格 X 数量+运费
			BigDecimal refoundAmout = (orderDetailPo.getProductPrice())
					.multiply(new BigDecimal(productNum))
					.subtract(orderDetailPo.getSellerCouponAmount())
					.subtract(orderDetailPo.getYmtCouponAmount())
					.subtract(orderDetailPo.getYmtPromotionAmount())
					.subtract(
							Utils.zeroIfNull(orderDetailPo
									.getThirdpartyDiscount()))
					.subtract(orderDetailPo.getRebatePaidAmount())
					.add(orderDetailPo.getFreight());

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setApplyRefundCount(productNum);
			validateRefundReq.setApplyRefundAmount(refoundAmout
					.add(BigDecimal.ONE));
			validateRefundReq.setCatalogId(catalogId);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_029() {
		Logger.start(true, "购买海淘达人会员订单，申请退货退款失败");

		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceAnliOrderCallService
					.placeMultiProAnlihuiOrder(BigDecimal.TEN, false, 3);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_STATUS_NOTMATCH",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("已购买的安利会员订单不能发起退货退款", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_030() {
		Logger.start(true, "订单商品满减包邮,申请单个商品退款");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			Order order = placeOrderResp.getOrderList().get(0);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund);

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_031() {
		Logger.start(true, "订单商品满减包邮,申请单个商品退款+运费，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithThreeProcutInTwoOrder(true,
							BigDecimal.ZERO, userId,
							LogisticsTypeEnum.OVERSEAS_DELIVERY);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			long userId = placeOrderResp.getUserId();
			long tradingId = placeOrderResp.getTradingId();
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			BigDecimal payAmount = placeOrderResp.getPayableAmount();

			// 支付订单
			TradingCallService.payOrder(userId, payAmount, tradingId);
			// 接单
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			// 商家发货
			TradingCallService.delivery(sellerId, orderId, false);
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Thread.sleep(5000);

			Order order = placeOrderResp.getOrderList().get(0);

			// 第一个订单下的第一个商品
			OrderDetailPo orderInfoPo = order.getOrderDetailPoList().get(0);

			int productNum = orderInfoPo.getProductCount();

			// 计算订单总价格 商品价格 X 数量
			BigDecimal refoundAmout = orderInfoPo.getProductPrice()
					.multiply(new BigDecimal(productNum))
					.subtract(orderInfoPo.getYmtCouponAmount())
					.subtract(orderInfoPo.getSellerCouponAmount())
					.add(orderInfoPo.getFreight());

			// 单件商品可退金额
			BigDecimal oneProRefund = refoundAmout.divide(new BigDecimal(
					productNum), 2, BigDecimal.ROUND_DOWN);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderInfoPo.getCatalogId());

			validateRefundReq.setApplyRefundAmount(oneProRefund);

			validateRefundReq.setApplyRefundCount(1);

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);

			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_032() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 部分退货退款，申请退款金额小于商品可退鉴别费金额，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Logger.comment("前置数据准备结束");
			
			BigDecimal userAuthenticateFee = order.getUserAuthenticateFee(1);

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));
			validateRefundReq.setApplyRefundAuthenticateFee(userAuthenticateFee);

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款金额不能小于商品可退鉴别费金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_033() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 部分退货退款，申请退款金额大于商品可退鉴别费金额，用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Logger.comment("前置数据准备结束");
			
			BigDecimal userAuthenticateFee = order.getUserAuthenticateFee(1);

			validateRefundReq.setApplyRefundAmount(userAuthenticateFee
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());
			validateRefundReq.setApplyRefundAuthenticateFee(userAuthenticateFee);
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_034() {
		Logger.start(true,
				"买家承担鉴定费和鉴定物流费, 部分退货退款，申请退款金额大于商品可退鉴别费金额+商品总额+运费，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(
							AuthenticateFreightTypeEnum.BUYER, BigDecimal.ONE,
							AuthenticateFeeTypeEnum.BUYER, BigDecimal.TEN);
			Long userId = placeOrder.getUserId();

			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			BigDecimal userAuthenticateFee = order.getUserAuthenticateFee(1);
			BigDecimal productPrice = order.getOrderDetailPoList().get(0)
					.getProductPrice();
			BigDecimal freight = order.getOrderFreight();

			validateRefundReq.setApplyRefundAmount(userAuthenticateFee
					.add(productPrice).add(freight).add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_035() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 全部退货退款申请退款金额小于商品可退鉴别费金额+可退鉴别费运费，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount()));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款鉴别费金额错误！", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_036() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 全部退货退款申请退款金额大于商品可退鉴别费金额+可退鉴别费运费，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee())
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_037() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 全部退货退款申请退款金额等于商品可退鉴别费金额+鉴别运费+运费+商品金额，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(orderDetailPo.getProductCount()));

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_038() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 全部退货退款申请退款金额大于商品可退鉴别费金额+鉴别运费+运费+商品金额，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(orderDetailPo.getProductCount()));

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(totalProductPrice)
					.add(order.getOrderFreight())
					.add(order.getUserAuthenticateFee(orderDetailPo
							.getProductCount()))
					.add(order.getUserAuthenticateFreightFee())
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_039() {
		Logger.start(true, "买手承担鉴定费和物流费, 全部退货退款申请退款金额>运费+商品金额，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.SELLER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.SELLER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(orderDetailPo.getProductCount()));

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight())
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("申请退款金额不能大于实际可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_040() {
		Logger.start(true, "买手承担鉴定费和物流费, 部分退货退款申请，申请金额<运费+商品金额，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.SELLER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.SELLER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(BigDecimal.ONE);
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_041() {
		Logger.start(true, "买手承担鉴定费和物流费, 全部退货退款申请退款金额=运费+商品金额，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.SELLER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.SELLER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(orderDetailPo.getProductCount()));

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight()));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_042() {
		Logger.start(true, "订单包含普通商品和买家鉴定费商品, 普通商品已经退款，全部退货退款，申请退款金额等于商品可退鉴别费金额+鉴别运费+运费+商品金额，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService.buildStandPlaceOrderReq();
			
			Long userId = placeOrderReq.getUserId();

			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellername);

			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();

			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());

			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);

			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService
					.createOrderItemVo(product.getProductId(),
							product.getCatalogId());

			String normalCatalogId = orderItemVo_order1_1.getCatalogId();

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(sellerId,
					sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String buyerAuthenticateCatalogId = orderItemVo_order1_2
					.getCatalogId();

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);

			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1,
					orderItemVo_order1_2));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));
			
			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			// 找到普通商品
			OrderDetailPo normalOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(normalCatalogId))
					.collect(Collectors.toList()).get(0);
			
			// 退第一个普通商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			RefundService.buildSingleApplyRefundReq(orderId,
					normalOrderDetailPo, refundedFreight);
			
			Logger.comment("前置数据准备结束");
			
			// 找到带有鉴定费商品
			OrderDetailPo authenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(buyerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);
			
			BigDecimal totalProductPrice = authenticateOrderDetailPo.getProductPrice()
					.multiply(new BigDecimal(authenticateOrderDetailPo.getProductCount()));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(
							authenticateOrderDetailPo.getProductCount())
					.add(totalProductPrice)
					.add(order.getOrderFreight().subtract(refundedFreight))
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setApplyRefundCount(authenticateOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(
							authenticateOrderDetailPo.getProductCount()).add(
							order.getUserAuthenticateFreightFee()));
			validateRefundReq.setCatalogId(authenticateOrderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, authenticateOrderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_043() {
		Logger.start(true, "订单包含普通商品和买家鉴定费商品, 普通商品全部退款+订单运费，校验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService.buildStandPlaceOrderReq();
			
			Long userId = placeOrderReq.getUserId();

			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellername);

			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();

			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());

			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);

			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService
					.createOrderItemVo(product.getProductId(),
							product.getCatalogId());

			String normalCatalogId = orderItemVo_order1_1.getCatalogId();

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(sellerId,
					sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);

			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1,
					orderItemVo_order1_2));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));
			
			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			// 找到普通商品
			OrderDetailPo normalOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(normalCatalogId))
					.collect(Collectors.toList()).get(0);
			
			Logger.comment("前置数据准备结束");
			
			BigDecimal totalProductPrice = normalOrderDetailPo.getProductPrice()
					.multiply(new BigDecimal(normalOrderDetailPo.getProductCount()));

			validateRefundReq.setApplyRefundAmount(totalProductPrice.add(order
					.getOrderFreight()));
			validateRefundReq.setApplyRefundCount(normalOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(normalOrderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, normalOrderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_044() {
		Logger.start(true,
				"订单包含普通商品和买家鉴定费商品, 其他商品没有发起退款，全部退货退款申请退款金额等于商品可退鉴别费金额+鉴别运费+运费+商品金额，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			Long userId = placeOrderReq.getUserId();

			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellername);

			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();

			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());

			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);

			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService
					.createOrderItemVo(product.getProductId(),
							product.getCatalogId());

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(sellerId,
					sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String buyerAuthenticateCatalogId = orderItemVo_order1_2
					.getCatalogId();

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);

			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1,
					orderItemVo_order1_2));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			// 找到带有鉴定费商品
			OrderDetailPo authenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(buyerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			BigDecimal totalProductPrice = authenticateOrderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(authenticateOrderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(
							authenticateOrderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setApplyRefundCount(authenticateOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(authenticateOrderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_045() {
		Logger.start(true,
				"订单包含普通商品和买家鉴定费商品, 其他商品没有发起退款，全部退货退款申请退款金额等于商品可退鉴别费金额+运费+商品金额，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			Long userId = placeOrderReq.getUserId();

			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellername);

			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();

			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());

			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);

			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService
					.createOrderItemVo(product.getProductId(),
							product.getCatalogId());

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(sellerId,
					sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String buyerAuthenticateCatalogId = orderItemVo_order1_2
					.getCatalogId();

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);

			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1,
					orderItemVo_order1_2));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();

			Logger.comment("前置数据准备结束");

			// 找到带有鉴定费商品
			OrderDetailPo authenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(buyerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			BigDecimal totalProductPrice = authenticateOrderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(authenticateOrderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(
							authenticateOrderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight()));
			validateRefundReq.setApplyRefundCount(authenticateOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(authenticateOrderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(authenticateOrderDetailPo
							.getProductCount()));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款鉴别费金额错误！", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_046() {
		Logger.start(true,
				"订单包含普通商品、买手鉴定费商品、买家鉴定费商品, 其他商品全部发起退款，全部退货退款申请，退款金额等于商品可退鉴别费金额+运费+商品金额，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			Long userId = placeOrderReq.getUserId();
			
			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellername);
			
			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();
			
			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());
			
			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);
			
			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService.createOrderItemVo(
					product.getProductId(), product.getCatalogId());
			
			String normalCatalogId = orderItemVo_order1_1.getCatalogId();						

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(
					sellerId, sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String buyerAuthenticateCatalogId = orderItemVo_order1_2.getCatalogId();

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);
			
			// 第三个商品，买手鉴别费
			pro = TradingProductVo.createPro(sellerId, sellername, 100);

			OrderItemVo orderItemVo_order1_3 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String sellerAuthenticateCatalogId = orderItemVo_order1_2.getCatalogId();
			
			orderItemVo_order1_3
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.SELLER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);
			
			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1, orderItemVo_order1_2, orderItemVo_order1_3));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));
			
			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			// 找到普通商品
			OrderDetailPo normalOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(normalCatalogId))
					.collect(Collectors.toList()).get(0);

			// 退第一个普通商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			RefundService.buildSingleApplyRefundReq(orderId,
					normalOrderDetailPo, refundedFreight);
			
			// 找到买手鉴定费商品
			OrderDetailPo sellerAuthenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(sellerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			// 退买手鉴定费商品
			RefundService.buildSingleApplyRefundReq(orderId,
					sellerAuthenticateOrderDetailPo, BigDecimal.ZERO);

			Logger.comment("前置数据准备结束");

			// 找到带有买家鉴定费商品
			OrderDetailPo buyerAuthenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(buyerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			BigDecimal totalProductPrice = buyerAuthenticateOrderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(buyerAuthenticateOrderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(
							buyerAuthenticateOrderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight()).subtract(refundedFreight));
			validateRefundReq.setApplyRefundCount(buyerAuthenticateOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(buyerAuthenticateOrderDetailPo
					.getCatalogId());
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(
							buyerAuthenticateOrderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, buyerAuthenticateOrderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_047() {
		Logger.start(true,
				"订单包含普通商品、买手鉴定费商品、买家鉴定费商品, 其他商品全部发起退款，全部退货退款申请，退款金额等于商品可退鉴别费金额+鉴别运费+运费+商品金额，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService
					.buildStandPlaceOrderReq();

			Long userId = placeOrderReq.getUserId();
			
			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellername);
			
			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();
			
			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());
			
			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);
			
			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService.createOrderItemVo(
					product.getProductId(), product.getCatalogId());
			
			String normalCatalogId = orderItemVo_order1_1.getCatalogId();						

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(
					sellerId, sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String buyerAuthenticateCatalogId = orderItemVo_order1_2.getCatalogId();

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);
			
			// 第三个商品，买手鉴别费
			pro = TradingProductVo.createPro(sellerId, sellername, 100);

			OrderItemVo orderItemVo_order1_3 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String sellerAuthenticateCatalogId = orderItemVo_order1_2.getCatalogId();
			
			orderItemVo_order1_3
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.SELLER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);
			
			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1, orderItemVo_order1_2, orderItemVo_order1_3));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));
			
			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());

			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			// 找到普通商品
			OrderDetailPo normalOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(normalCatalogId))
					.collect(Collectors.toList()).get(0);

			// 退第一个普通商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			RefundService.buildSingleApplyRefundReq(orderId,
					normalOrderDetailPo, refundedFreight);
			
			// 找到买手鉴定费商品
			OrderDetailPo sellerAuthenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(sellerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			// 退买手鉴定费商品
			RefundService.buildSingleApplyRefundReq(orderId,
					sellerAuthenticateOrderDetailPo, BigDecimal.ZERO);

			Logger.comment("前置数据准备结束");

			// 找到带有买家鉴定费商品
			OrderDetailPo buyerAuthenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(buyerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			BigDecimal totalProductPrice = buyerAuthenticateOrderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(buyerAuthenticateOrderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(
							buyerAuthenticateOrderDetailPo.getProductCount())
					.add(totalProductPrice).add(order.getOrderFreight()).add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(buyerAuthenticateOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(buyerAuthenticateOrderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_048() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 先退一件商品+部分运费，退剩下所有商品，申请退款金额=商品可退鉴别费金额+运费+鉴别费+鉴别运费，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			// 先退一个商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			Integer refundedProductCount = 1;
			RefundService.buildSingleApplyRefundReq(orderId, orderDetailPo,
					refundedFreight, refundedProductCount);
			
			Logger.comment("前置数据准备结束");
			
			Integer applyProductCount = orderDetailPo.getProductCount()
					- refundedProductCount;
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(applyProductCount));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(applyProductCount)
					.add(order.getUserAuthenticateFreightFee())
					.add(totalProductPrice).add(order.getOrderFreight())
					.subtract(refundedFreight));
			validateRefundReq.setApplyRefundCount(applyProductCount);
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(applyProductCount).add(
							order.getUserAuthenticateFreightFee()));
			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_049() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 先退一件商品+部分运费，再退一件商品，申请退款金额=商品可退鉴别费金额+运费+鉴别费+鉴别运费，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			// 先退一个商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			Integer refundedProductCount = 1;
			RefundService.buildSingleApplyRefundReq(orderId, orderDetailPo,
					refundedFreight, refundedProductCount);
			
			Logger.comment("前置数据准备结束");
			
			Integer applyProductCount = 1;
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(applyProductCount));

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(applyProductCount)
					.add(order.getUserAuthenticateFreightFee())
					.add(totalProductPrice).add(order.getOrderFreight())
					.subtract(refundedFreight));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_050() {
		Logger.start(true, "先退一件商品+部分运费，再退一件商品，申请退款金额>商品可退金额+运费，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingCallService.payOrder();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			// 先退一个商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			Integer refundedProductCount = 1;
			
			RefundService.buildSingleApplyRefundReq(orderId, orderDetailPo,
					refundedFreight, refundedProductCount);
			
			Logger.comment("前置数据准备结束");
			
			Integer applyProductCount = 1;
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(applyProductCount));

			validateRefundReq.setApplyRefundAmount(totalProductPrice
					.add(order.getOrderFreight()));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_051() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 部分退货退款，申请的买家鉴别费大于可退鉴别费金额，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(1));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(1).add(BigDecimal.ONE));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款鉴别费金额错误！", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_052() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 部分退货退款，申请的买家鉴别费小于可退鉴别费金额，审核失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(1));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(1).subtract(BigDecimal.ONE));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(String.format("订单%s申请退款鉴别费金额错误！", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_053() {
		Logger.start(true, "先退一件商品+部分运费，再退一件商品，申请退款数量>商品总数，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingCallService.payOrder();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);
			
			// 先退一个商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			Integer refundedProductCount = 1;
			
			RefundService.buildSingleApplyRefundReq(orderId, orderDetailPo,
					refundedFreight, refundedProductCount);
			
			Logger.comment("前置数据准备结束");
			
			Integer applyProductCount = 1;
			
			BigDecimal totalProductPrice = orderDetailPo.getProductPrice()
					.multiply(new BigDecimal(applyProductCount));

			validateRefundReq.setApplyRefundAmount(totalProductPrice
					.add(order.getOrderFreight()).subtract(refundedFreight));
			validateRefundReq.setApplyRefundCount(orderDetailPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ERR_CONDITION_NOTMATCH",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("申请退商品数量不能大于实际商品数量", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_054() {
		Logger.start(true, "订单包含普通商品和买家鉴定费商品, 买家鉴定费商品已经退款，普通商品全部退货退款，申请退款金额等于鉴别运费+运费+商品金额，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService.buildStandPlaceOrderReq();
			
			Long userId = placeOrderReq.getUserId();

			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellername);

			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();

			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());

			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);

			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService
					.createOrderItemVo(product.getProductId(),
							product.getCatalogId());

			String normalCatalogId = orderItemVo_order1_1.getCatalogId();

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(sellerId,
					sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());
			String buyerAuthenticateCatalogId = orderItemVo_order1_2
					.getCatalogId();

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);

			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1,
					orderItemVo_order1_2));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));
			
			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			// 找到带有鉴定费商品
			OrderDetailPo authenticateOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(buyerAuthenticateCatalogId))
					.collect(Collectors.toList()).get(0);

			// 退第一个鉴定费商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			ApplyRefundReq applyRefundReq = RefundService.buildSingleApplyRefundReq(orderId,
					authenticateOrderDetailPo, refundedFreight);
			RefundService.applyRefundCall(applyRefundReq);
			
			Logger.comment("前置数据准备结束");
			
			// 找到普通商品
			OrderDetailPo normalOrderDetailPo = order
					.getOrderDetailPoList()
					.stream()
					.filter(orderDetailPo -> orderDetailPo.getCatalogId()
							.equalsIgnoreCase(normalCatalogId))
					.collect(Collectors.toList()).get(0);

			BigDecimal totalProductPrice = normalOrderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(normalOrderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(totalProductPrice.add(
					order.getOrderFreight().subtract(refundedFreight)).add(
					order.getUserAuthenticateFreightFee()));
			validateRefundReq.setApplyRefundCount(normalOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFreightFee());
			validateRefundReq.setCatalogId(normalOrderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款鉴别费金额错误！", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_055() {
		Logger.start(true, "订单包含多个买家鉴定费商品, 其中一个买家鉴定费商品已经退款，另外一个全部退货退款，申请退款金额等于商品最大可退鉴定费金额+鉴别运费+运费+商品金额，申请成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
			String sellername = EnvSetup.getData("autotest_sellerName1");

			PlaceOrderReq placeOrderReq = TradingCallService.buildStandPlaceOrderReq();
			
			Long userId = placeOrderReq.getUserId();

			// 第一个订单组
			OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
					sellerId, sellername);

			// 第一个订单
			OrderVo orderVo1 = TradingCallService.createOrderVo();

			orderVo1.withAuthenticateFreight(BigDecimal.ONE)
					.withAuthenticateFreightType(
							AuthenticateFreightTypeEnum.SELLER.getCode());

			// 创建一个普通商品
			TradingProductVo product = TradingProductVo.createPro(sellerId,
					sellername, 100);

			// 第一个商品
			OrderItemVo orderItemVo_order1_1 = TradingCallService
					.createOrderItemVo(product.getProductId(),
							product.getCatalogId());

			// 第二个商品，买家鉴别费
			TradingProductVo pro = TradingProductVo.createPro(sellerId,
					sellername, 100);

			OrderItemVo orderItemVo_order1_2 = TradingCallService
					.createOrderItemVo(pro.getProductId(), pro.getCatalogId());

			orderItemVo_order1_2
					.withAuthenticateFlag(true)
					.withAuthenticateFeeType(
							AuthenticateFeeTypeEnum.BUYER.getCode())
					.withAuthenticateFee(BigDecimal.TEN);

			orderVo1.setOrderItems(Arrays.asList(orderItemVo_order1_1,
					orderItemVo_order1_2));
			orderGroupVo.setOrders(Arrays.asList(orderVo1));
			placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));
			
			TradingServiceResp placeOrder = TradingCallService
					.callPlaceOrderService(placeOrderReq);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			// 退第一个鉴定费商品
			BigDecimal refundedFreight = BigDecimal.ONE;
			ApplyRefundReq applyRefundReq = RefundService.buildSingleApplyRefundReq(orderId,
					order.getOrderDetailPoList().get(0), refundedFreight);
			RefundService.applyRefundCall(applyRefundReq);
			
			Logger.comment("前置数据准备结束");
			
			// 退第二个鉴定费商品
			OrderDetailPo normalOrderDetailPo = order.getOrderDetailPoList()
					.get(1);

			BigDecimal totalProductPrice = normalOrderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(normalOrderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(totalProductPrice
					.add(order.getOrderFreight().subtract(refundedFreight))
					.add(order.getUserAuthenticateFreightFee())
					.add(RefundService.getUserAuthenticateFee(
							normalOrderDetailPo,
							normalOrderDetailPo.getProductCount())));
			validateRefundReq.setApplyRefundCount(normalOrderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFreightFee().add(
							RefundService.getUserAuthenticateFee(
									normalOrderDetailPo,
									normalOrderDetailPo.getProductCount())));
			validateRefundReq.setCatalogId(normalOrderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, normalOrderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_056() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 鉴定中心发货，全部退货退款=商品可退金额+商品可退运费+商品可退鉴定费+鉴定物流费，校验失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			Long sellerId = order.getSellerId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);
			
			// 国际段发货
			TradingCallService.delivery(sellerId, orderId, LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 1, true);
			
			// 鉴定中心发货
			TradingCallService.authenticateDelivery(sellerId, orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee())
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款鉴别费金额错误！", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_057() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 鉴定中心发货，全部退货退款=商品可退金额+商品可退运费+商品可退鉴定费，校验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			Long sellerId = order.getSellerId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);
			
			// 国际段发货
			TradingCallService.delivery(sellerId, orderId, LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 1, true);
			
			// 鉴定中心发货
			TradingCallService.authenticateDelivery(sellerId, orderId);
			Thread.sleep(3000);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount()));
			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_058() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 确认收货，全部退货退款=商品可退金额+商品可退运费+商品可退鉴定费+鉴定物流费，校验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			Long sellerId = order.getSellerId();
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			Thread.sleep(3000);
			
			// 国际段发货
			TradingCallService.delivery(sellerId, orderId, LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 1, true);
			
			// 确认收货
			TradingCallService.confirmReceive(userId, orderId);

			Logger.comment("前置数据准备结束");

			validateRefundReq.setApplyRefundAmount(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee())
					.add(order.getUserAuthenticateFreightFee())
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFee(orderDetailPo.getProductCount())
					.add(order.getUserAuthenticateFreightFee()));
			validateRefundReq.setCatalogId(orderDetailPo.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_059() {
		Logger.start(true, "买家承担鉴定费和鉴定物流费, 部分退货退款，申请退款金额大于商品可退鉴别费金额，用户支付后接单前效验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticate(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Logger.comment("前置数据准备结束");
			
			BigDecimal userAuthenticateFee = order.getUserAuthenticateFee(1);

			validateRefundReq.setApplyRefundAmount(userAuthenticateFee
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(1);
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());
			validateRefundReq.setApplyRefundAuthenticateFee(userAuthenticateFee);
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, order.getOrderDetailPoList().get(0),
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_060() {
		Logger.start(true, "一个买家鉴定费商品，一个普通商品， 接单前，买家鉴定费商品全部退货退款，退款金额>商品可退鉴别费金额+鉴别运费，校验成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticateWithTwoTypeProduct(AuthenticateFreightTypeEnum.BUYER,
							BigDecimal.ONE, AuthenticateFeeTypeEnum.BUYER,
							BigDecimal.TEN);
			Long userId = placeOrder.getUserId();
			
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Logger.comment("前置数据准备结束");
			
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().stream()
					.filter(od -> od.getAuthenticateFlag() == true)
					.collect(Collectors.toList()).get(0);
			BigDecimal userAuthenticateFee = order.getUserAuthenticateFee(
					orderDetailPo.getProductCount()).add(
					order.getUserAuthenticateFreightFee());

			validateRefundReq.setApplyRefundAmount(userAuthenticateFee
					.add(BigDecimal.ONE));
			validateRefundReq.setApplyRefundCount(orderDetailPo.getProductCount());
			validateRefundReq.setOrderId(orderId);

			validateRefundReq.setCatalogId(order.getOrderDetailPoList().get(0)
					.getCatalogId());
			validateRefundReq.setApplyRefundAuthenticateFee(userAuthenticateFee);
			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			verify(order, orderDetailPo,
					validateRefundReq.getApplyRefundCount());

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ValidateRefundV2_061() {
		Logger.start(true, "订单包含多个买家鉴定费商品, 第一个买家鉴定费商品全部退货退款，申请退款金额等于商品最大可退鉴定费金额+鉴别运费+运费+商品金额，申请失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			
			TradingServiceResp placeOrder = TradingPlaceAuthenticateCallService
					.placeOrderWithAuthenticateWithTwoProduct(
							AuthenticateFreightTypeEnum.BUYER, BigDecimal.ONE,
							AuthenticateFeeTypeEnum.BUYER, BigDecimal.TEN);
			
			Long userId = placeOrder.getUserId();

			TradingCallService.payOrder(userId, placeOrder.getPayableAmount(),
					placeOrder.getMainOrderId());
			
			Order order = placeOrder.getOrderList().get(0);
			Long orderId = order.getOrderId();
			
			Logger.comment("前置数据准备结束");
			
			// 退第一个个鉴定费商品
			OrderDetailPo orderDetailPo = order.getOrderDetailPoList()
					.get(0);

			BigDecimal totalProductPrice = orderDetailPo
					.getProductPrice().multiply(
							new BigDecimal(orderDetailPo
									.getProductCount()));

			validateRefundReq.setApplyRefundAmount(totalProductPrice
					.add(order.getOrderFreight())
					.add(order.getUserAuthenticateFreightFee())
					.add(RefundService.getUserAuthenticateFee(
							orderDetailPo,
							orderDetailPo.getProductCount())));
			validateRefundReq.setApplyRefundCount(orderDetailPo
					.getProductCount());
			validateRefundReq.setOrderId(orderId);
			validateRefundReq.setApplyRefundAuthenticateFee(order
					.getUserAuthenticateFreightFee().add(
							RefundService.getUserAuthenticateFee(
									orderDetailPo,
									orderDetailPo.getProductCount())));
			validateRefundReq.setCatalogId(orderDetailPo
					.getCatalogId());

			validateRefundReq.setRefundBillNo(String.format("TK%s", orderId));

			applyvalidationCall.setData(validateRefundReq);
			applyvalidationCall.callService();

			Logger.verifyEquals("false",
					applyvalidationCall.getString("success"), "验证返回码");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applyvalidationCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单%s申请退款金额不能大于商品最大可退款金额", orderId),
					applyvalidationCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
